Menu

Custom Console Commands

Zathrus Writer

Custom Console Commands

This is an event handling function that monitors console commands and changes them based on settings from a config file.

This function loads command replacements from file called consolecmd.txt (unless file name is changed in the plugin config file), located in the CommandsEX directory in your plugins folder. If the config file doesn't exist, it will be created automatically.


How to remove this feature

Should there be a need to manually remove this feature from the JAR file, the following file must be removed: com/github/zathrus_writer/commandsex/handlers/Handler_replaceconsolecommand.class


Configuration file syntax

CommandsEX uses regular expressions to match commands against texts provided in the config file. You can use any regular expression supported by Java and test them here (basic stuff) or here (advanced stuff).

The actual format of your config file must follow this principle:

  • /console command/ ==> replacement command
  • /{ci}console command, case insensitive/ ==> replacement command
  • /{cc}console command, keeping letter case/ ==> replacement uppercased command

For scripting (e.g. to replace 1 command with multiple others), use the following syntax:

/console command/ =={
    1st command to execute
    2nd command to execute
    ....
}

Please note that the closing bracket -> } <- must always be at the beginning of a line.

The {ci} and {cc} switches are special to CommandsEX. They must be listed at the beginning of the regular expression. As the example above states, if {ci} is used, CommandsEX will search for the command given ignoring letter case. This way, you can easily catch typos like "/helP", "/Help" etc.

The {cc} switch will check if the command entered in the console is uppercase and if it is, CommandsEX will automatically make the command replacement uppercase as well.


Back references support

CommandsEX supports back references following java's model (e.g. $1 - $9), adding reference $p for player's name (not display name, but the real user name).

These are some more examples of how back references work (these are applicable to player commands and are here only for reference):

  • /cmode/ ==> gamemode $p 1 (switches game mode of the player to creative)
  • /smode/ ==> gamemode $p 0 (switches game mode of the player to survival)
  • /promote (.*)/ ==> pex promote $1
  • /demote (.*)/ ==> pex demote $1

Known caveats:

Command words (regexes matching against the chat which execute commands) run the commands before the chat message is broadcast, instead of afterward. The commands are still run in response to what you say in chat, it just doesn't seem like it...


Credits:

This functionality has been merged from the former Commander plugin, developed by tustin2121


Related

Wiki: CommandsEX CraftBukkit plugin Wiki
Wiki: Configuration

MongoDB Logo MongoDB